package cn.myframe.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;

import cn.myframe.utils.validate.ValidateResult;
import cn.myframe.utils.validate.ValidatorUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 校验提交数据格式是否正确
 * 
 * @author ynz
 * @email ynz@myframe.cn
 * @date 2018年7月31日 下午4:59:50
 */
@Aspect
@Component
@Slf4j
public class ValidateAspect {
	 
	/*@Around(("execution(* cn.myframe..*.save(..))"))*/
	public Object valid(ProceedingJoinPoint  joinPoint) throws Throwable{
		log.debug("check method[save] data Validate......");
		//请求的参数
		Object[] args = joinPoint.getArgs();
		log.debug(JSON.toJSONString(args[0]));
		ValidateResult result = ValidatorUtil.validator(args[0]);
		if(!result.isSuccess()){
			//return R.error(result.getErrMsg()[0]);
		}
		Object o = joinPoint.proceed();
		return o;

	}

}
